<template>
    <div>
				<div class="tips" v-if="!userinfo.openId">请先登录再进行查看</div>
        <comment type="comment" :comment="commentList" v-if="commentList.length"></comment>
				<div class="books" v-if="userinfo.openId">
					<div class="top-title">添加过的图书</div>
					<div class="tips" v-if="!bookList.length">您没有添加过图书，快去添加一本图书吧</div>
					<card v-for="book in bookList" :key="book.id" :book="book"></card>
				</div>
		</div>
</template>

<script>
import { get } from '@/util'
import Comment from '@/components/CommentList/CommentList'
import Card from '@/components/Card/Card'
export default {
	components:{
		Comment,
		Card
	},
	data(){
		return {
			userinfo: {},
			commentList: [],
			bookList: []
		}
	},
	onPullDownRefresh() {
		this.init()
		wx.stopPullDownRefresh()
	},
	methods: {
		init() {
			wx.showNavigationBarLoading()
			this.userinfo = wx.getStorageSync('userinfo')
			if(this.userinfo){
				this.getComment()
				this.getBookList()
			}
			wx.hideNavigationBarLoading()
		},
		async getComment () {
			let res = await get('/weapp/commentlist', {
				openid: this.userinfo.openId
			})
			this.commentList = res.msg
		},
		async getBookList () {
			let res = await get('/weapp/booklist',{
				openid: this.userinfo.openId
			})
			this.bookList = res.msg
		}
	},
  onShow () {
		this.init()
	}
}
</script>

<style lang="stylus" scoped>
	@import '~style/varibles'
	.tips
		color $themeColor
		text-align center
		font-size 14px
		margin-top 20px
</style>

